# -*- coding: utf-8 -*-

from apps.common.base import BaseHandler
from apps.plugins.validcode import ValidCodeImg

class RuaptchaHandler(BaseHandler):

    async def get(self, *args, **kwargs):
        t = self.get_argument('t', default='')
        data, code = ValidCodeImg(code_count=4).getValidCodeImg()
        if t:
            self.cache_action.ruaptcha().set(t, code)
        self.set_header('Content-type', 'image/png')
        self.write(data)
